package com.wlyuan.open.scanner.utils.enums;

import com.wlyuan.core.marker.NamedValue;
import com.wlyuan.core.marker.NamedValueMap;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.RequiredArgsConstructor;

import java.util.Map;
import java.util.Optional;

/**
 * @author lijing
 */
@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
@Getter
public enum StatusEnum implements NamedValue<Integer> {
    ENABLED(1, "有效"), DISABLED(0, "无效");

    private final Integer value;
    private final String name;

    private static final Map<Integer, StatusEnum> MAP = new NamedValueMap<>(StatusEnum.class);

    public static StatusEnum fromValue(Integer value) {
        return Optional.ofNullable(value).map(StatusEnum::get).orElse(null);
    }

    private static StatusEnum get(Integer val) {
        return MAP.get(val);
    }
}
